using SQLRunnerLib.DB;

namespace SQLRunnerLib.DB
{
	/// <summary>
	/// Summary description for SQLUtil.
	/// </summary>
	public class SQLUtil
	{
		public enum SQLApp {QueryAnalyzer=8, Sqlwb=9, Sql10K = 10}

		#region Constructors
		
		public SQLUtil(){}

		#endregion
		#region Public Methods

		public string SqlApplicationFactory( int version )
		{
			string arg = "";
			if ( version <  ((int)SQLApp.Sqlwb) )
			{
				arg = "isqlw.exe";
			}
			else if ( version == (int) SQLApp.Sqlwb)
			{
			    arg = "sqlwb.exe";
			}
			else if ( version == (int) SQLApp.Sql10K)
			{
                arg = "ssms.exe";
			}
			return arg;
		}

		public string SqlArgumentFactory( int version, SQLArguments args )
		{
			string arg = "";
			if ( version <  ((int)SQLApp.Sqlwb) )
			{
				arg = "-f\"" + args.FileName + "\"";
				arg += " -S" + args.ServerName;
				arg += " -d" + args.DatabaseName;
				if ( args.Trusted )
				{
					arg += " -E";
				}
				else
				{
					arg += " -U" + args.UserName + " -P" + args.UserPwd;
				}
			}
			else
			{
				arg = "\"" + args.FileName + "\"";
				arg += " -S " + args.ServerName;
				arg += " -d " + args.DatabaseName;
				if ( args.Trusted)
				{
					arg += " -E";
				}
				else
				{
					arg += " -U" + args.UserName + " -P" + args.UserPwd;
				}
				arg += " -nosplash";
			}
			return arg;
		}

		#endregion

	}
}
